package study.cell_game.objects.borders;

import java.util.HashMap;

import org.andengine.entity.sprite.Sprite;

import study.cell_game.enums.Direction;

public class Border {

	private int currentSpriteIndex = 0;
	private Sprite[] rotationSprites; // type of the cell border

	private HashMap<Direction, Boolean>[] inbound; // = new
													// HashMap<Direction,Boolean>();
	private HashMap<Direction, Boolean>[] outbound;// = new
													// HashMap<Direction,Boolean>();

	public boolean canEnterVia(Direction dir) {
		return inbound[currentSpriteIndex].get(dir);
	}

	public boolean canLeaveVia(Direction dir) {
		return outbound[currentSpriteIndex].get(dir);
	}

	public Sprite getActiveSprite() {
		return rotationSprites[currentSpriteIndex];
	}

	/**
	 * TODO: this method might require fixes, not sure yet.
	 * @param dir
	 */
	public void rotate(Direction dir) {
		this.currentSpriteIndex += dir.getValue();
		this.currentSpriteIndex %= rotationSprites.length;
	}

	public void rotateClockwise(){
		this.currentSpriteIndex ++;
		this.currentSpriteIndex %= rotationSprites.length;
	}
	
	Border() {
	}

	Border(HashMap<Direction, Boolean>[] inbound, HashMap<Direction, Boolean>[] outbound, Sprite[] sprites) {
		this.outbound = outbound;
		this.inbound = inbound;
		this.rotationSprites = sprites;
	}
	
}
